********************************************************************************
* Purpose: placebo tests
********************************************************************************

do "D:\Data\workdata\708296\Project - Mother groups and mental health\Do\global.do" 

use "$work\final_data1", clear

********************************************************************************
*Figure C9: Random placebo tests
********************************************************************************

* randomize high score - keep groups
forvalues i = 1/1000 {
set seed `i'
gen ran_high = runiform(0,1)
gen high_p = 0
replace high_p = 1 if ran_high > 0.9245
rangestat high_p, int(group 0 0) excludeself
gen peer_treat_plac = 0
replace peer_treat_plac = 1 if high_p_mean > 0
eststo clear
eststo: areg anyw24 peer_treat_plac, absorb(time fe mfr_first) vce(cluster group)
mat beta = e(b)	
svmat double beta, names(matcol)
rename betapeer_treat_plac beta_`i'
drop peer_treat_plac beta_cons high_p high_p_mean ran_high
carryforward beta_`i', replace
}
keep if _n == 1
keep beta_*
gen n = 1
reshape long beta_, i(n)
save "$work\random_any2", replace

use "$work\random_any2",clear
hist beta_, bin(15) graphregion(color(white)) bgcolor(color) lcolor(white) color(gs11) ylab(,labcolor(black) glcolor(gs10%33) angle(horizontal) tlcolor(gs10) tlwidth(medthick) ticks) xlab(-0.02(0.01)0.02,labcolor(black) glcolor(gs10%33) angle(horizontal) tlcolor(gs10) tlwidth(medthick) ticks) ///
legend(off) xtitle("Estimated placebo coefficient") ysize(7) xsize(10) yscale(line noextend nofextend lcolor(gs10) lwidth(medthick)) xscale(line noextend nofextend lcolor(gs10) lwidth(medthick)) graphregion(lcolor(white) fcolor(white)) ytitle(,color(black)) xline(0.017) graphregion(color(white) lcolor(white)) plotregion(color(white) lcolor(white))
graph export "$out\random_any2.png", replace

use "$work\final_data1", clear

forvalues i = 1/1000 {
set seed `i'
gen ran_high = runiform(0,1)
gen high_p = 0
replace high_p = 1 if ran_high > 0.9245
rangestat high_p, int(group 0 0) excludeself
gen peer_treat_plac = 0
replace peer_treat_plac = 1 if high_p_mean > 0
eststo clear
eststo: areg consw24 peer_treat_plac, absorb(time fe mfr_first) vce(cluster group)
mat beta = e(b)	
svmat double beta, names(matcol)
rename betapeer_treat_plac beta_`i'
drop peer_treat_plac beta_cons high_p high_p_mean ran_high
carryforward beta_`i', replace
}
keep if _n == 1
keep beta_*
gen n = 1
reshape long beta_, i(n)
save "$work\random_cons", replace

use "$work\random_cons",clear
hist beta_, bin(15) graphregion(color(white)) bgcolor(color) lcolor(white) color(gs11) ylab(,labcolor(black) glcolor(gs10%33) angle(horizontal) tlcolor(gs10) tlwidth(medthick) ticks) xlab(-0.02(0.01)0.02,labcolor(black) glcolor(gs10%33) angle(horizontal) tlcolor(gs10) tlwidth(medthick) ticks) ///
legend(off) xtitle("Estimated placebo coefficient") ysize(7) xsize(10) yscale(line noextend nofextend lcolor(gs10) lwidth(medthick)) xscale(line noextend nofextend lcolor(gs10) lwidth(medthick)) graphregion(lcolor(white) fcolor(white)) ytitle(,color(black)) xline(0.014) graphregion(color(white) lcolor(white)) plotregion(color(white) lcolor(white))
graph export "$out\random_cons.png", replace

use "$work\final_data1", clear

forvalues i = 1/1000 {
set seed `i'
gen ran_high = runiform(0,1)
gen high_p = 0
replace high_p = 1 if ran_high > 0.9245
rangestat high_p, int(group 0 0) excludeself
gen peer_treat_plac = 0
replace peer_treat_plac = 1 if high_p_mean > 0
eststo clear
eststo: areg adm24 peer_treat_plac, absorb(time fe mfr_first) vce(cluster group)
mat beta = e(b)	
svmat double beta, names(matcol)
rename betapeer_treat_plac beta_`i'
drop peer_treat_plac beta_cons high_p high_p_mean ran_high
carryforward beta_`i', replace
}
keep if _n == 1
keep beta_*
gen n = 1
reshape long beta_, i(n)
save "$work\random_adm", replace

use "$work\random_adm",clear
hist beta_, bin(15) graphregion(color(white)) bgcolor(color) lcolor(white) color(gs11) ylab(,labcolor(black) glcolor(gs10%33) angle(horizontal) tlcolor(gs10) tlwidth(medthick) ticks) xlab(-0.02(0.01)0.02,labcolor(black) glcolor(gs10%33) angle(horizontal) tlcolor(gs10) tlwidth(medthick) ticks) ///
legend(off) xtitle("Estimated placebo coefficient") ysize(7) xsize(10) yscale(line noextend nofextend lcolor(gs10) lwidth(medthick)) xscale(line noextend nofextend lcolor(gs10) lwidth(medthick)) graphregion(lcolor(white) fcolor(white)) ytitle(,color(black)) xline(0.005) graphregion(color(white) lcolor(white)) plotregion(color(white) lcolor(white))
graph export "$out\random_adm.png", replace

use "$work\final_data1", clear

forvalues i = 1/1000 {
set seed `i'
gen ran_high = runiform(0,1)
gen high_p = 0
replace high_p = 1 if ran_high > 0.9245
rangestat high_p, int(group 0 0) excludeself
gen peer_treat_plac = 0
replace peer_treat_plac = 1 if high_p_mean > 0
eststo clear
eststo: areg psykw24 peer_treat_plac, absorb(time fe mfr_first) vce(cluster group)
mat beta = e(b)	
svmat double beta, names(matcol)
rename betapeer_treat_plac beta_`i'
drop peer_treat_plac beta_cons high_p high_p_mean ran_high
carryforward beta_`i', replace
}
keep if _n == 1
keep beta_*
gen n = 1
reshape long beta_, i(n)
save "$work\random_psyk", replace

use "$work\random_psyk",clear
hist beta_, bin(15) graphregion(color(white)) bgcolor(color) lcolor(white) color(gs11) ylab(,labcolor(black) glcolor(gs10%33) angle(horizontal) tlcolor(gs10) tlwidth(medthick) ticks) xlab(-0.02(0.01)0.02,labcolor(black) glcolor(gs10%33) angle(horizontal) tlcolor(gs10) tlwidth(medthick) ticks) ///
legend(off) xtitle("Estimated placebo coefficient") ysize(7) xsize(10) yscale(line noextend nofextend lcolor(gs10) lwidth(medthick)) xscale(line noextend nofextend lcolor(gs10) lwidth(medthick)) graphregion(lcolor(white) fcolor(white)) ytitle(,color(black)) xline(0.008) graphregion(color(white) lcolor(white)) plotregion(color(white) lcolor(white))
graph export "$out\random_psyk.png", replace



